﻿

import Request from "../../base/request.js?t=202511041006"
import Storage from "../../base/storage.js?t=202511041006"
import { imageBaseUrl, downloadfun, isImageFile, queryURLParams, easyCopy, getBrowserInfo } from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {

    const generateh = (text, isShort) => {
        if (isShort) {
            return h('div', {
                style: "width:100px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis; -o-text-overflow: ellipsis;cursor:pointer"
            }, { default: () => text })
        } else {
            return h('div', {
                style: "width:300px;height:auto;"
            }, { default: () => text })
        }

    }

    const data = reactive({
        messageTest: "",
        proxy: "",
        popShow: false,
        popTitle: '',
        uploadImg: {
            previewVisible: false,
            previewImage: "",
            previewTitle: "",
            fileList: [

            ]
        },
        imgUrl: "",
        previewShow: false,
        itemRender: (data) => {

            let uid = data.file.uid
            const previewBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnPreview(uid) }, src: "../Bussiness/img/svg/preview.svg", width: 20, height: 22 }, { default: () => '预览' })
            const downloadBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDownLoad(uid) }, src: "../Bussiness/img/svg/download.svg", width: 20, height: 22 }, { default: () => '下载' })
            const deleteBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDelete(uid) }, src: "../Bussiness/img/svg/delete.svg", width: 18, height: 22 }, { default: () => '删除' })
            var btns = ""


            if (isImageFile(data.file.url)) {


                btns = h('div', { style: "display:flex;margin-left:10px" }, {
                    default: () => [
                        previewBtn,
                        downloadBtn,
                        deleteBtn
                    ]
                })

            } else {


                btns = h('div', { style: "display:flex;margin-left:10px" }, {
                    default: () => [
                        downloadBtn,
                        deleteBtn
                    ]
                })
            }

            return h('div', { style: 'margin-top:10px; width:400px;align-items:center; display:flex;justify-content:space-between' }, {
                default: () => [
                    data.file.name, btns
                ]
            })

        },
        uploadLock: false,
        pagination: {
            total: 0,
            current: 1,
            loading: false,
            pageSize: 10,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗

        },
        urlParams: {},
        columns: [
            {
                title: '序号',
                dataIndex: 'a',
                key: 'a',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
            {
                title: '测试b',
                dataIndex: 'b',
                key: 'b',
                align: 'center'

            },
            {
                title: '通知部门',
                dataIndex: 'Departments',
                key: 'Departments',
                align: 'center',
                customRender: function ({ text, record }) {


                    let content = h('div', {
                        style: 'width:700px'
                    }, { default: () => record.Departments.map(e => e.DepartmentName).join(` , `) });


                    let textc = h(antd.Button, {
                        type: "link"
                    }, { default: () => record.Departments.length });

                    return h(antd.Popover, {
                        title: '通知部门',
                        content: content,

                    }, () => [textc]);
                }
            },
            {
                title: '发布日期',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'center',
                customRender: function ({ text, record }) {
                    return dealTime(text)
                }
            },
            {
                title: '发布人',
                dataIndex: 'CreateUserName',
                key: 'CreateUserName',
                align: 'center',
                customRender: function ({ text, record }) {
                    return `${record.CreateUserName}(${record.CreateUser})`
                }
            },
            {
                title: '状态',
                dataIndex: 'Status',
                key: 'Status',
                align: 'center',
                width: '100px',
                customRender: function ({ text }) {

                    return h(antd.Tag, {
                        color: text == '1' ? "#108ee9" : "#87d068",
                        style: 'cursor:pointer'
                    }, { default: () => text == 1 ? '发布' : '保存' });




                }
            },




            {
                title: '操作',
                key: 'action',
                align: 'center',
                fixed: 'right',
                width: 100,
                customRender: function ({ text, record, index, column }) {

                    const returnBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link"
                    }, { default: () => '撤回' })

                    const fReturnBtn = h(antd.Popconfirm, {
                        title: "确定撤回此数据？",
                        onConfirm: () => methods.handleReturn(record.Id)

                    }, { default: () => returnBtn })



                    const delBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link"
                    }, { default: () => '删除' })

                    const fDelBtn = h(antd.Popconfirm, {
                        title: "确定删除此数据？",
                        onConfirm: () => methods.handleDelete(record.Id)

                    }, { default: () => delBtn })


                    const modifyBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link",
                        onClick: () => methods.handleModify(record)
                    }, { default: () => '编辑' })



                    const publicBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link",
                        onClick: () => methods.handlePublic(record)
                    }, { default: () => '通知' })



                    const detailBtn = h(antd.Button, {
                        style: 'margin-right:4px',
                        type: "link",
                        onClick: () => methods.handleDetail(record)
                    }, { default: () => '详情' })







                    return h(antd.Space, {
                    },
                        () => [fReturnBtn, modifyBtn, fDelBtn, publicBtn, detailBtn]
                    );

                }
            },
        ],
        dataSource: [],



    })
    let params = toRefs(data)
    const methods = {
        setVisible: (value) => {
            params.previewShow.value = value;
        },
        test: () => {
            params.imgUrl.value = "https://assets.msn.cn/weathermapdata/1/static/weather/Icons/taskbar_v10/Condition_Card/CloudyV3.svg"
            methods.setVisible(true)
        },
        btnPreview: (e) => {
            let item = params.uploadImg.value.fileList.find(es => es.uid == e)
            params.imgUrl.value = item.url
            methods.setVisible(true)
        },
        btnDownLoad: (e) => {
            let item = params.uploadImg.value.fileList.find(es => es.uid == e)
            const { name, url } = item
            downloadfun(name, url)

        },
        btnDelete: (e) => {
            params.uploadImg.value.fileList = params.uploadImg.value.fileList.filter(es => es.uid != e)
        },
        handleChange: (info) => {

            if (!params.uploadLock.value) {
                params.uploadLock.value = true
                let formData = new FormData();
                formData.append('nfile', info.file.originFileObj)
                formData.append('uid', info.file.originFileObj.uid)
                Request({
                    url: "/download/uploadfile?Path=PPE/Apply",
                    method: 'post',
                    data: formData
                }).then(res => {

                    let item = params.uploadImg.value.fileList.find(e => e.uid == res.Data[0].uid)
                    item.url = imageBaseUrl + res.Data[0].FilePath.split('../..')[1]
                    item.FileId = res.Data[0].FileId
                    item.FileName = res.Data[0].FileName
                    item.name = res.Data[0].FileName
                    params.uploadLock.value = false


                })
            }



        },

        handlePopOk: () => {



            params.popShow.value = false
        },





        filterOption: (val, type) => {
            return `${type.label}`.includes(`${val || ''}`)
        },




        handleCancel: () => {
            params.uploadImg.value.previewVisible = false;
            params.uploadImg.value.previewTitle = '';
        },








        onBack: () => {
            window.location.href = ``
        },

        onSubmit: (Status) => {




        },
        init: () => {
              getBrowserInfo().catch(err => { console.log(err)})
            if (proxy) {
                params.proxy.value = proxy
            }
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });


            let info = Storage.get('AccountInfo', true)
            Request({
                url: "/Account/createJwtToken",
                method: 'post',
                data: {
                    "userName": info && info.UserNo
                }
            }).then(res => {
                params.urlParams.value = queryURLParams()
                Storage.set('token', res.Data,true)
            })
        },

    }
    const template = {
        previewImg: {
            template: `
            <a-image :width="600"
                     :style="{ display: 'none',zIndex:100 }"
                     :preview="{visible:previewShow,onVisibleChange:setVisible}" :src="imgUrl"></a-image>
            `, setup() {

                return {
                    ...params,
                    ...methods,
                };
            }
        },
        bottomBtns: {
            template: `<div class="w-full bg-[#eeeeee] h-50  flex  items-center justify-end pr-4">
                    <a-space>
  <a-popconfirm
    title="确定执行此操作?"
    ok-text="确定"
    cancel-text="取消"
    @confirm="onSubmit(0)"
  >
 <a-button  :loading="uploadLock" type="dashed">保存</a-button>
  </a-popconfirm>

  <a-popconfirm
    title="确定执行此操作?"
    ok-text="确定"
    cancel-text="取消"
    @confirm="onSubmit(1)"
  >
          <a-button  :loading="uploadLock" type="primary">提交</a-button>
  </a-popconfirm>
                       
              
                        <a-button v-on:click="onBack" :loading="uploadLock">返回</a-button>
                    </a-space>
                </div>`,
            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }
    return {
        ...params,
        ...methods,
        template
    }
}
export default Composition